***** RUN DO_MASTER.do ***** do "$Do_files\DO_MASTER.do"

global program "OA_TableB35"
cap log close
cap log using "$Log_files\log_$program$today", replace

**** REPLICATION OF TABLE B.3.5 ****

clear all
set mem 2g
set more off

// Import data

use $Data\data_news_voting, clear

// Get controls

global ctrl_base	"sh_lde lpop_A sh_F sh_F_new sh_cspsup sh_sec sh_ter lmean_reink lmean_reink2 charact_altitude charact_altitude_std sh_active sh_young sh_prot sh_M mk com_property"
global ctrl_plus	"mean_votation lcrSR_F_N"
global fe			"charact_agglo"
global fe_iv		"I_charact_agglo_*"
global cluster		"charact_agglo"

// Column 1
		
reghdfe oui instr_dev_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing
estimates store RF_true_ctrl

// Column 2

cap drop endog_priors_mk
cap g endog_priors_mk=endog_true_mk
reghdfe endog_priors_mk instr_dev_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	
estimates store FS_true_ctrl
test instr_dev_mk
estadd scalar F_fs=r(F)
		
// Column 3

reghdfe oui $ctrl_plus $ctrl_base (endog_priors_mk = instr_dev_mk) ///
	if sample_hq00dstr==1, ///
	vce(cluster $cluster) absorb($fe) stages(first, eform(exp(beta)) ) keepsing	old
estimates store TSLS_true_ctrl

// Column 4
		
reghdfe oui instr_dev_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing
estimates store RF_pop_ctrl

// Column 5

cap drop endog_priors_mk
cap g endog_priors_mk=endog_local_mk
reghdfe endog_priors_mk instr_dev_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	
estimates store FS_pop_ctrl
test instr_dev_mk
estadd scalar F_fs=r(F)
		
// Column 6

reghdfe oui $ctrl_plus $ctrl_base (endog_priors_mk = instr_dev_mk) ///
	if sample_hq00dstr==1, ///
	vce(cluster $cluster) absorb($fe) stages(first, eform(exp(beta)) ) keepsing	old
estimates store TSLS_pop_ctrl

// Labels

la var endog_priors_mk 		"Crime News Exposure ($\mathtt{CNE}$)"
la var instr_dev_mk 		"[0.1em] HQ $ \mathtt{CPD} $ Deviation ($ \mathtt{\Delta HQC} $)"
la var lcrSR_F_N 			"[0.1em] Local $ \mathtt{CPD} $"
la var mean_votation 		"[0.1em] Past Vote Outcomes"

// Table
	
estout RF_true_ctrl FS_true_ctrl TSLS_true_ctrl RF_pop_ctrl FS_pop_ctrl TSLS_pop_ctrl ///
	using "$Results\\$program.tex", replace style(tex) type label	///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(N r2_a F_fs, lab("Observations" "Adjusted $ R^2 $" "First-stage F-statistic") fmt(0 3 2)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	keep(endog_priors_mk lcrSR_F_N mean_votation instr_dev_mk) /// 
	order(endog_priors_mk lcrSR_F_N mean_votation instr_dev_mk) ///	
	title(News and voting: Alternative coding rules for news without nationality) ///		
	prehead("\begin{table}[!h]" ///
	"\begin{center}" ///
	"\begin{threeparttable}" ///
	"\begin{footnotesize}" ///
	"\caption{\small{@title}\label{$program}}" ///
	"\begin{tabular*}{\columnwidth}{@{\extracolsep{\stretch{1}}}l*{@M}{c}@{}}" ///
	"\hline" "\hline" ///	
	"\\" ///
	"%Specification 		&\multicolumn{6}{c}{Two-Stage Least-Squares (2SLS)} \\" ///
	"%					\cmidrule(lr){2-7}	" ///
	"Specification 		&\multicolumn{3}{c}{True nationality}															&\multicolumn{3}{c}{Locality distribution} \\" ///
	"					\cmidrule(lr){2-4}																				\cmidrule(lr){5-7}" ///
	"					&\multicolumn{1}{c}{RF}			&\multicolumn{1}{c}{FS}			&\multicolumn{1}{c}{2SLS}		&\multicolumn{1}{c}{RF}		&\multicolumn{1}{c}{FS}		&\multicolumn{1}{c}{2SLS} \\" ///
	"					\cmidrule(lr){2-2} 				\cmidrule(lr){3-4}				\cmidrule(lr){5-5}				\cmidrule(lr){6-7}" ///
	"Dependent Variable &\multicolumn{1}{c}{\%Yes} 		&\multicolumn{1}{c}{$ \mathtt{CNE} $}		&\multicolumn{1}{c}{\%Yes}		&\multicolumn{1}{c}{\%Yes} 		&\multicolumn{1}{c}{$ \mathtt{CNE} $}		&\multicolumn{1}{c}{\%Yes}	\\" ///
	"					\cmidrule(lr){2-4}												\cmidrule(lr){5-7} 							" ///
	"					&\multicolumn{1}{c}{(1)} 		&\multicolumn{1}{c}{(2)}  		&\multicolumn{1}{c}{(3)} 		&\multicolumn{1}{c}{(4)}  	&\multicolumn{1}{c}{(5)} &\multicolumn{1}{c}{(6)} \\") ///
	posthead("\hline" ///
	"\\") ///
	prefoot("\\" ///
	"\hline") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" /// 
	"\end{footnotesize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" /// 
	"The unit of observation is a municipality. " ///
	"Standard errors clustered at agglomeration level in parentheses. " ///
	"{$^c$} significant at 10\%; {$^b$} significant at 5\%; {$^a$} significant at 1\%. " ///
	"Columns (1) to (3) present 2SLS estimation when the true (reported) nationality of aggressor is imputed for news that do not report the perpetrators' nationalities; " ///
	"Columns (4) to (6) when the share of foreigners in the municipality where the crime took place is imputed. " ///
	"%Columns (1) and (4) present the reduced form estimation; Columns (2) and (5) the first-stage; Columns (3) and (6) the second-stage estimates. " ///
	"All regressions include the full vector of controls of Table \ref{Main_Table2}. " ///
	"" ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}" ///
	"\end{center}" ///
	"\end{table}")

cap log close
